﻿angular.module('Finance')
.factory("WebAPI", [function () {

    var Result = function (url, data) {

        this.data = {
            method: "POST",
            url: url,
            data: data,
            cache: false
        };
    }

    return {

        getHttpSettings: function (url, data) {

            var result = new Result(url, data);
            return result.data;
        }
    };
}]).factory('Bank', ["$http", "WebAPI", function ($http, WebAPI) {
    return {
        save: function (bank) {
            return $http(WebAPI.getHttpSettings("Bank/Save", { bank: bank }));
        },
        query: function (name, offset, count) {
            return $http(WebAPI.getHttpSettings("Bank/Query", { name: name, offset: offset, count: count }));
        },
        get: function (code) {
            return $http(WebAPI.getHttpSettings("Bank/Get", { code: code }));
        }
    };
}]).factory('Deposit', ["$http", "WebAPI", function ($http, WebAPI) {
    return {
        save: function (bank) {
            return $http(WebAPI.getHttpSettings("Deposit/Save", { model: bank }));
        },
        query: function (name, offset, count) {
            return $http(WebAPI.getHttpSettings("Deposit/Query", { name: name, offset: offset, count: count }));
        },
        get: function (code) {
            return $http(WebAPI.getHttpSettings("Deposit/Get", { code: code }));
        },
        remove: function (model) {
            return $http(WebAPI.getHttpSettings("Deposit/Remove", { model: model }));
        }
    };
}]).factory('Active', ["$http", "WebAPI", function ($http, WebAPI) {
    return {
        save: function (bank) {
            return $http(WebAPI.getHttpSettings("Active/Save", { model: bank }));
        },
        query: function (name, offset, count) {
            return $http(WebAPI.getHttpSettings("Active/Query", { name: name, offset: offset, count: count }));
        },
        get: function (code) {
            return $http(WebAPI.getHttpSettings("Active/Get", { code: code }));
        },
        remove: function (model) {
            return $http(WebAPI.getHttpSettings("Active/Remove", { model: model }));
        },
        showResults: function (model) {
            return $http(WebAPI.getHttpSettings("Active/ShowResults", { model: model }));
        }
    };
}]).factory('Accounting', ["$http", "WebAPI", function ($http, WebAPI) {
    return {
        calculate: function (model) {
            return $http(WebAPI.getHttpSettings("Accounting/Calculate", { model: model }));
        },
        effect: function (model) {
            return $http(WebAPI.getHttpSettings("Accounting/CalculateEffect", { model: model }));
        },
        yieldperiod: function (model) {
            return $http(WebAPI.getHttpSettings("Accounting/CalculateYieldPeriod", { model: model }));
        },
        yieldyear: function (model) {
            return $http(WebAPI.getHttpSettings("Accounting/CalculateYieldYear", { model: model }));
        },
        amount: function (model) {
            return $http(WebAPI.getHttpSettings("Accounting/CalculateAmount", { model: model }));
        }       
    };
}]);